package com.hdq.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hdq.mapper.CouponMapper;
import com.hdq.mapper.SkusMapper;
import com.hdq.result.PageResult;
import com.hdq.service.CouponService;
import dto.CouponAddDTO;
import dto.CouponEditDTO;
import dto.SkusAddDTO;
import dto.SkusEditDTO;
import entity.Coupon;
import entity.Skus;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vo.CouponPageVO;
import vo.SkusPageVO;

import java.util.List;

@Service
public class CouponServiceImpl implements CouponService {

    @Autowired
    private CouponMapper couponMapper;
    @Override
    public PageResult selectByPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        Page<CouponPageVO> list=couponMapper.selectByPage();
        return new PageResult(list.getTotal(),list.getResult());

    }

    @Override
    public void insert(CouponAddDTO couponAddDTO) {
        Coupon coupon = new Coupon();
        BeanUtils.copyProperties(couponAddDTO,coupon);
        couponMapper.insert(coupon);
    }


    @Override
    public void delete(List<Long> ids) {
        couponMapper.delete(ids);
    }


    @Override
    public void update(CouponEditDTO couponEditDTO) {
        Coupon coupon = new Coupon();
        BeanUtils.copyProperties(couponEditDTO,coupon);
        couponMapper.update(coupon);
    }
}
